package com.icode.applet;

import java.applet.Applet;

/**
 * Created with IntelliJ IDEA.
 * User: ZhongGang
 * Date: 14-7-17
 * Time: 下午10:47
 * <p/>
 * Q: what is java applet?
 * A: Java Applet is a fragment java program which runs in the browser
 */
public class GraphicApplet extends Applet {
    private String message;
    private Integer horizontal;
    private Integer vertical;

    /**
     * the init method is invoked when the applet is initialized
     */
    @Override
    public void init() {
        System.out.println("init method start");
        this.message = getParameter("message");
        this.horizontal = Integer.valueOf(getParameter("horizontal"));
        this.vertical = Integer.valueOf(getParameter("vertical"));
        System.out.println("init method finish");
    }

    /**
     * the start method is invoked when the html page is loaded
     */
    @Override
    public void start() {
        System.out.println("start method start");
        getGraphics().drawString(message, horizontal, vertical);
        System.out.println("start method finish");
    }

    /**
     * the stop method is invoked when user goes to other html pages
     */
    @Override
    public void stop() {
        System.out.println("stop method start");
        this.message = null;
        this.horizontal = null;
        this.vertical = null;
        System.out.println("stop method finish");
    }

    /**
     * the destroy method is invoked when the browser is closed
     */
    @Override
    public void destroy() {
        System.out.println("destroy method start");
        this.message = null;
        this.horizontal = null;
        this.vertical = null;
        System.out.println("destroy method finish");
    }
}
